import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * The MotherShip is the most difficult enemy to kill and its considerated the boss enemy.
 * 
 * @author (Arturo Aaron Rios Obregon) 
 * @version (30 june 2013)
 */
public class MotherShip extends Enemy
{
    private SimpleTimer cTimer;
    private SimpleTimer LTimer;
    private boolean lsr;
    private boolean inlcreated;
    private boolean lcreated;
    /**
     * Constructor
     */
    public MotherShip()
    {
        super(800);
        cTimer = new SimpleTimer();
        cTimer.mark();
        LTimer = new SimpleTimer();
        LTimer.mark();
        lsr=false;
        inlcreated=false;
        lcreated=false;
    }
    
    /**
     * The act method makes move the MotherShip, check if it touch bullets
     * and eliminate she if her life is zero.
     */
    public void act() 
    {
        mueve();        
        disparaLaser();
        super.tocaBala();
        switch(Greenfoot.getRandomNumber(3))
        {
            case 0:
                if(cTimer.millisElapsed()/1000>6)
                {
                   dispara(); 
                   cTimer.mark();
                }
            case 1:
                if(cTimer.millisElapsed()/1000>6)
                {
                   creaEnemigos(); 
                   cTimer.mark();
                }
            case 2:
                if(cTimer.millisElapsed()/1000>6)
                {
                   lsr=true; 
                   cTimer.mark();
                }
        }        
        super.vidaCero();
    }  
    
    /**
     * This method create the killer laser from the MotherShip
     */
    public void disparaLaser()
    {
        if(lsr==false)
            LTimer.mark();
        else
            if(LTimer.millisElapsed()/1000<3&&inlcreated==false)
            {
                IniLaser l = new IniLaser();
                getWorld().addObject(l,getX()+12,getY()+50);
                inlcreated=true;
            }
            else if(LTimer.millisElapsed()/1000>3&&LTimer.millisElapsed()/1000<5&&lcreated==false)
            {
                LaserMadre ls = new LaserMadre();
                getWorld().addObject(ls,getX()+12,getY()+210);
                lsr=false;
                inlcreated=false;
                lcreated=true;
            }
            else if(LTimer.millisElapsed()/1000>5)
            {
                lcreated=false;
                lsr=false;
                inlcreated=false;
            }
    }
    
    /**
     * This method create DupEnemies to help
     */
    public void creaEnemigos()    
    {
        DupEnemy n1 = new DupEnemy();
        getWorld().addObject(n1,getX()+20,getY()+70);
        DupEnemy n2 = new DupEnemy();
        getWorld().addObject(n2,getX()+60,getY()+70);
        DupEnemy n3 = new DupEnemy();
        getWorld().addObject(n3,getX()-20,getY()+70);
        
        
    }
    
    /**
     * This method make the MotherShip shut.
     */
    public void dispara()
    {
        BulletEnemy b1 = new BulletEnemy();
        getWorld().addObject(b1,getX()+23,getY()+23);
        BulletEnemy b2 = new BulletEnemy();
        getWorld().addObject(b2,getX()+23,getY()+112);
        BulletEnemy b3 = new BulletEnemy();
        getWorld().addObject(b3,getX()+280,getY()+50);
        BulletEnemy b4 = new BulletEnemy();
        getWorld().addObject(b4,getX()+220,getY()+108);
        BulletEnemy b5 = new BulletEnemy();
        getWorld().addObject(b5,getX()-223,getY()+45);
        BulletEnemy b6 = new BulletEnemy();
        getWorld().addObject(b6,getX()-165,getY()+95);
    }
    
    /**
     * This methos move the MotherShip.
     */
    public void mueve()
    {
        if(getY()<101)
            setLocation(getX(),getY()+1);
    }
}
